﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace cubo
{
    //Barras de combustivel, velocidade, altura, ...
    class HUD
    {
        Nave nave;

        float combustivelMax;
        float combustivel;
        float razaoTotalAtual;
        float complementarRazao;

        float alturaNave;

        int escore;
        

        Texture2D texturaCombustivel;
        Texture2D texturaHUDCombustivel;

        Texture2D texturaAltura;
        Texture2D texturaHUDAltura;

        SpriteFont fonteEscore;

        Rectangle retanguloTela;

        public HUD(Nave nave, Texture2D fuelTexture, Texture2D fuelHUDTexture, Texture2D heightTexture, Texture2D heightHUDTexture, Rectangle screenRect, SpriteFont font)
        {
            this.nave = nave;
            this.combustivelMax = nave.getCombustivelMax();

            this.texturaCombustivel = fuelTexture;
            this.texturaHUDCombustivel = fuelHUDTexture;

            this.texturaAltura = heightTexture;
            this.texturaHUDAltura = heightHUDTexture;

            this.retanguloTela = screenRect;
            this.fonteEscore = font;

            this.razaoTotalAtual = 1.0f;
            this.alturaNave = 0.0f;

            this.escore = 0;
            
        }


        public void Update(GameTime gameTime)
        {
            combustivel = nave.getCombustivel();

            //Console.WriteLine("Combustivel: " + combustivel);
            //Console.WriteLine("CombustivelMax: " + combustivelMax);

            razaoTotalAtual = combustivel / combustivelMax;

            complementarRazao = 1.0f - razaoTotalAtual;

            alturaNave = nave.getPosicao().Y;

            //Console.WriteLine("Altura da nave: " + alturaNave);
        }

        
        public void Draw(SpriteBatch spriteBatch)
        {
            //Console.WriteLine("Razao[int]: " + razaoTotalAtual); 
            
            spriteBatch.Begin();

            //Pintando o combustivel atual.
            spriteBatch.Draw(texturaCombustivel, new Rectangle(25,(int)(40 + complementarRazao*460),50,(int) (razaoTotalAtual * 460)), new Rectangle(0, 0, 50, 474), Color.White);
           

            //pintando a máscara por fora.
            spriteBatch.Draw(texturaHUDCombustivel, new Vector2(0, 20), Color.White);


            //Pintando a altura atual.
            spriteBatch.Draw(texturaAltura, new Rectangle(retanguloTela.Width - texturaHUDAltura.Width + 25, (int)(500 - alturaNave * 5), 50, (int)(alturaNave * 5)), new Rectangle(0, 0, 50, 474), Color.White);

            //Pintando a máscara por fora.
            spriteBatch.Draw(texturaHUDAltura, new Vector2(retanguloTela.Width - texturaHUDAltura.Width, 20), Color.White);

            spriteBatch.DrawString(this.fonteEscore, "Placar: " + escore, new Vector2(this.retanguloTela.Width/2 - 70, 10), Color.White);
            
            
            spriteBatch.End();
            
            
            
            
           
        }
    }

    
}
